﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VisualPoint.Controls.Models;
using VisualPoint.Controls.Views;

namespace VisualPoint.Controls.ViewModels
{
    public class WindowsConfigurationsViewModel : BaseModel
    {

        public WindowsConfigurationsViewModel()
        {
            Model = new WindowsConfigurationModel();
        }

        public WindowsConfigurationModel Model
        {
            get;
            set;
        }

        private string _Message;
        public string Message
        {
            get
            {
                return _Message;
            }
            set
            {
                _Message = value;
                DoPropertyChanged("Message");
            }
        }


        public void Create(string value)
        {
            if (!string.IsNullOrWhiteSpace(value))
            {
                try
                {
                    VisualPoint.Controls.Environments.Environment.Current.CreateWindowConfiguration(value);
                    Message = string.Format("Created {0}", value);
                }
                catch (Exception ex)
                {
                    Message = ex.Message;
                }
                Initialize();
            }

        }

        public void Delete()
        {
            string value = Model.SelectedValue;
            if (!string.IsNullOrWhiteSpace(value))
            {
                try
                {
                    VisualPoint.Controls.Environments.Environment.Current.DeleteWindowConfiguration(value);
                    Message = string.Format("Deleted {0}", value);
                }
                catch (Exception ex)
                {
                    Message = ex.Message;
                }
                Initialize();
            }
        }

        public void Update()
        {
            string value = Model.SelectedValue;
            if (!string.IsNullOrWhiteSpace(value))
            {
                try
                {
                    VisualPoint.Controls.Environments.Environment.Current.UpdateWindowConfiguration(value);
                    Message = string.Format("Update {0}", value);
                }
                catch (Exception ex)
                {
                    Message = ex.Message;
                }
            }
        }

        public void Initialize()
        {
            Model.Configurations = VisualPoint.Controls.Environments.Environment.Current.GetWindowConfigurations();
            Model.SelectedValue = VisualPoint.Controls.Environments.Environment.Current.GetActiveWindowConfiguration();
        }
    }
}
